package com.example.home.house.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.house.bean.HouseListBean;
import com.example.home.tool.OKHttpTool;

import static com.example.home.tool.StaticActi.ip;

public class HouseDetailsActivity extends AppCompatActivity {
    private ImageView back;
    private ImageView detailsImg;
    private TextView detailsText;
    private TextView detailsMianji;
    private TextView detailsPrice;
    private TextView detailsType;
    private TextView detailsCentent;
    private String listId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_house_details);
        Intent intent = getIntent();
        listId = intent.getStringExtra("house_id");
        initView();
        getData();
    }

    private void getData() {
        OKHttpTool.doNetRequest("prod-api/api/house/housing/"+listId,
                OKHttpTool.GET,
                HouseListBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        HouseListBean houseBean = (HouseListBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Glide.with(HouseDetailsActivity.this).load(ip+houseBean.getData().getPic()).into(detailsImg);
                                detailsText.setText(houseBean.getData().getSourceName());
                                detailsImg.setScaleType(ImageView.ScaleType.FIT_XY);
                                detailsMianji.setText("建筑面积:"+houseBean.getData().getAreaSize()+"m");
                                detailsPrice.setText("房源单价:"+houseBean.getData().getPrice());
                                detailsType.setText("房源类型:"+houseBean.getData().getHouseType());
                                detailsCentent.setText("房源介绍:"+houseBean.getData().getDescription());
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void initView() {
        back = findViewById(R.id.back);
        detailsImg = findViewById(R.id.details_img);
        detailsText = findViewById(R.id.details_text);
        detailsMianji = findViewById(R.id.details_mianji);
        detailsPrice = findViewById(R.id.details_price);
        detailsType = findViewById(R.id.details_type);
        detailsCentent = findViewById(R.id.details_centent);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HouseDetailsActivity.this.finish();
            }
        });

    }
}